package gui;

import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;

import javax.swing.ImageIcon;
import javax.swing.JLabel;

/**
 * Created when the user clicks on a sprite palette button. Follows the mouse
 * around.
 */
public class DraggableImage extends JLabel
{
    
    private ImageIcon icon;

    public DraggableImage(ImageIcon icon)
    {
        super(icon);
        this.icon = icon;
        this.setVisible(true);
        this.setOpaque(true);
        this.addMouseMotionListener(new MouseTracker());
        this.setBounds(20, 20, icon.getIconWidth(), icon.getIconHeight());
        System.out.println("New DraggableImage created.");
    }

    private class MouseTracker implements MouseMotionListener
    {
        public void mouseMoved(MouseEvent e)
        {
            int x = e.getX();
            int y = e.getY();
            DraggableImage.this.setBounds(x, y, icon.getIconWidth(), icon.getIconHeight());
        }
        
        public void mouseDragged(MouseEvent e)
        {
            return;
        }
    }

}
